/*
 * DBeaver - Universal Database Manager
 * Copyright (C) 2010-2024 DBeaver Corp and others
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.jkiss.dbeaver.erd.ui.export;

import org.eclipse.draw2d.IFigure;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.erd.ui.model.DiagramLoader;
import org.jkiss.dbeaver.erd.ui.model.EntityDiagram;
import org.jkiss.dbeaver.erd.ui.part.DiagramPart;
import org.jkiss.dbeaver.model.runtime.VoidProgressMonitor;
import org.jkiss.dbeaver.utils.GeneralUtils;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

public class ERDExportERD implements ERDExportFormatHandler {
    @Override
    public void exportDiagram(EntityDiagram diagram, IFigure diagramFigure, DiagramPart diagramPart, File targetFile) throws DBException {
        try (FileWriter writer = new FileWriter(targetFile, GeneralUtils.UTF8_CHARSET)) {
            writer.write(DiagramLoader.serializeDiagram(new VoidProgressMonitor(), diagramPart, diagram, false, true));
        } catch (IOException e) {
            throw new DBException("Error saving diagram", e);
        }
    }
}
